perm filename IPUPMD.H[11,HE] blob sn#688215 filedate 1982-12-06 generic text, type T, neo UTF8
#ifndef	PUPMACHDEPDEFINED	/* don't double-define these */
#define	PUPMACHDEPDEFINED
/*
 * pupmachdep.h
 *
 * Machine dependent part of Pup package.
 *
 * This is primarily meant to hide the byte-ordering problem
 * from the rest of the code.  We start with the concept of
 * a "network standard" byte order, which is the Alto ordering
 * of bytes.  PDP-11s and VAXen adhere to the opposite ordering.
 *
 * Packets contain arrays of short words; therefore, the following
 * points arise:
 *
 * reading/writing a short word in a buffer is considered
 * machine independent.
 *
 * read/writing a long word involves swapping the low and high
 * short words iff the host machine does not adhere to
 * network standard order.
 *
 * moving character arrays:
 * (1)	if the communication is between two machines with net standard
 *	order (NSO), use a block move.
 *
 * (2)	if communication is between two machines with net non-standard
 *	order (NNSO), use a block move but on odd buffers, byte-swap
 *	the last word to keep the garbage byte in the NSO last position.
 *
 * (3)	if communication is between an NSO machine and an NNSO machine,
 *	the NNSO machine must byte-swap all the words in the buffer.
 *
 * Packet structures:
 *	The PupPacket struct and the EnPacket struct must be
 *	defined differently, depending upon ordering of things
 *	like host #/net #.
 *
 * Rules to follow:
 *
 * In general: always
 *	o	retrieve longs from buffers using getlong()
 *	o	make longs for insertion into buffers using makelong()
 *	o	move strings into and out of buffers using movestring()
 *			except in case (2), above.
 *
 *	If you are in situation (2) of "moving character arrays", you
 *	may move strings into/out of Pup buffers with bmove (block move),
 *	AS LONG AS the Pup channel mode is set to PCM_RFIXLAST for
 *	reading and PCM_WFIXLAST for writing; this will avoid actual
 *	byte-swapping and will get the right result.
 *
 * The stuff below figures out what sort of machine you are on
 * from the -D option during compilation; the Makefile should
 * define one of these.
 */

#ifdef	VAX
#define	PUP__NNSO
#endif

#ifdef	PDP_11
#define	PUP__NNSO
#endif

#ifdef	MC68000
#define PUP__NSO
#endif

#ifdef	IBM_S1
#define PUP__NSO
#endif

/* to keep things simple for naive users, we default to VAX order
 * if no machine is specified.
 */
#ifndef	PUP__NSO
#ifndef PUP__NNSO

#define VAX		/* make sure that these two agree! */
#define	PUP__NNSO

#endif
#endif

/* define getlong, makelong, movestring */
#ifdef	PUP__NNSO

#define	getlong(x) ( ((x&0xFFFF)<<16) | ((x>>16)&0xFFFF) )
#define	makelong(x) ( ((x&0xFFFF)<<16) | ((x>>16)&0xFFFF) )
#define movestring(from,to,len) (swab(from,to,roundup(len)))

#endif

#ifdef	PUP__NSO

#define	getlong(x) (x)
#define	makelong(x)  (x)
#define movestring(from,to,len) (bmove(from,to,len))

#endif

#endif